/* map_data.h */

#ifndef DODO_MAP_DATA_H
#define DODO_MAP_DATA_H

#include <shapefil.h>
#include <string>
#include <list>

namespace dodo_plot
{

class Map_Data_Impl
{
	friend class Map_Data;
public:
	typedef std::list<SHPObject*>::iterator iterator;
	typedef std::list<SHPObject*>::const_iterator const_iterator;
//STL style interfaces
private:
	iterator begin();
	const_iterator begin() const;
	iterator end();
	const_iterator end() const;
	int size() const;
//other interfaces
private:
	int shape_type() const;
	double lon_min() const;
	double lon_max() const;
	double lat_min() const;
	double lat_max() const;
// constructors
private:
	Map_Data_Impl(const std::string& filename);
	Map_Data_Impl(const std::string& filename, 
		double lon_min, double lon_max,
		double lat_min, double lat_max);
	
	~Map_Data_Impl();  // to free the remaining pointers...
// helper function
	void load_from_file(const std::string& filename,
		bool check_range);
	double adjust_cross_180(double lon) const;
private: // smart ptr for Map_Data
	int use_count_;
	
private:
	// well, take care with the pointers...
	// free (not delete!) everything 
	// when they are out of the list.
	std::list<SHPObject*> data_;
	
	int shape_type_;
	double lon_min_, lon_max_;
	double lat_min_, lat_max_;
};

class Map_Data 
{
public:
	typedef Map_Data_Impl::iterator iterator;
	typedef Map_Data_Impl::const_iterator const_iterator;
//STL style interfaces
public:
	iterator begin();
	const_iterator begin() const;
	iterator end();
	const_iterator end() const;
	int size() const;
//other interfaces
public:
	int shape_type() const;
	double lon_min() const;
	double lon_max() const;
	double lat_min() const;
	double lat_max() const;
public:
	Map_Data(const std::string& filename);
	Map_Data(const std::string& filename,
		double lon_min, double lon_max,
		double lat_min, double lat_max);
	Map_Data(const Map_Data& orig);
	~Map_Data();
	
	Map_Data& operator= (const Map_Data& orig);

private:
	Map_Data_Impl* impl_;
};



}

#endif //DODO_MAP_DATA_H

